<?php
defined('SEJUJOPEFDNGJSL') or exit('Access denied');

$deid=getnums($_GET['deid'],0);
if(!empty($deid)){

	$db->query('select * from ld_article where id='.$deid,2);
	if(empty($db->rs)){
		show_automsg('文章不存在！',$GLOBALARR['curl'],1);
	}

	$db->sitedbexec('delete from ld_article where id='.$deid);
	record_log('删除文章:'.$db->rs['title']);
	show_automsg('删除文章成功！',$GLOBALARR['curl']);
}

$veid=getnums($_GET['veid'],0);
if(!empty($veid)){
	$db->query('select * from ld_article where id='.$veid,2);
	if(empty($db->rs)){
		show_automsg('文章不存在！',$GLOBALARR['curl'],1);
	}

	echo '<h3>文章阅读</h3>';
	echo '<div class="main-r-body"><div class="artview">
		标题：'.$db->rs['title'].'</div>'.$db->rs['content'].'
	</div><a href="javascript:history.go(-1)" class="artreturn">[ 返回 ]</a>';
		exit;
}

$pagecount=getnums($_GET["pagecount"],$GLOBALARR['pagecount']);
$option=getnums($_GET['option'],1);
$orderby=getnums($_GET['orderby'],1);
$quser=checkstr(trim($_GET['quser']));

$arrtype=getatricletype(array(4));

$tmp_arr['toption'].='<a href="'.getqueurl('option',1).'" class="'.geteqval(array($option,1,'taselbtn','thabtn')).'">所有文章</a>';
foreach ($arrtype as $k => $v) {
	$tmp_arr['toption'].='<a href="'.getqueurl('option',$k+2).'" class="'.geteqval(array($option,$k+2,'taselbtn','thabtn')).'">'.$v.'</a>';
}


$tmp_arr['torderby']='<a href="'.getqueurl('orderby',geteqval(array($orderby,1,'2','1'))).'" class="'.((strstr($orderby,'1')||strstr($orderby,'2'))?"tpaixusel":"tpaixu").'">'.geteqval(array($orderby,1,'时间↓','时间↑')).'</a>';


$tmp_arr['tcolor']='<a href="javascript:;" class="theacolor showcolor0">允许显示</a><a href="javascript:;" class="theacolor showcolor1">禁止显示</a>';



$condition=' where 1=1 ';

if($quser){
	if(strstr($quser,'-')){
		$qdate=explode('-',$quser);
		if($qdate[0]) $condition.=" and from_unixtime(art_time,'%Y')=".$qdate[0]."";
		if($qdate[1]) $condition.=" and from_unixtime(art_time,'%m')=".$qdate[1]."";
		if($qdate[2]) $condition.=" and from_unixtime(art_time,'%d')=".$qdate[2]."";
	}else{
		$condition.=" and title like '%".$quser."%'";
	}
}

if($option>1) $condition.=' and  attype='.($option-2);


$order='';
if($orderby==1) $order=' order by art_time desc';
if($orderby==2) $order=' order by art_time asc';


$tmp_arr['tth']='<th>序号</th><th>文章标题</th><th>文章类型</th><th>浏览次数</th><th>是否置顶</th><th>发布人</th><th>添加时间</th><th>操作</th>';

$psql="select count(0) from ld_article $condition";
$db->query($psql,3);
$pcount=$db->fval;
$pagecount=$pagecount;   //每页条数 
$astr="&lsaction=articlelist&pagecount=$pagecount&orderby=$orderby&option=$option&quser=$quser";	  //Url
$pagearr=pagelist($pagecount,$pcount,$astr);
$offset=$pagearr[1];

$sql="select * from ld_article  $condition $order limit $offset,$pagecount";
$db->query($sql);
$ii=0;
foreach ($db->rs as $k => $v) {
	$ii++;
	$serialid=($pagearr[2]-1)*$pagecount+$ii;
	$tmp_arr['ttr'].='<tr class="showcolor'.$v['is_show'].'">
						<td><span  title="'.$v["id"].'">'.$serialid.'</span></td>
						<td align="left">&nbsp;&nbsp;<a href="'.$GLOBALARR['curl'].'&veid='.$v['id'].'" class="alinktxt">'.$v['title'].'</a></td>
						<td>'.$arrtype[$v['attype']].'</td>
						<td>'.$v['view_times'].'</td>
						<td>'.geteqval(array($v['is_on_top'],0,'<span style="color:#555">否</span>','<span style="color:#f00">是</span>')).'</td>	
						<td>'.$v['author'].'</td>	
						<td>'.formatdate($v['art_time']).'</td>	
						<td><a href="'.YMCURL.'articleedit&edid='.$v['id'].'">修改</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="'.$GLOBALARR['curl'].'&deid='.$v['id'].'" onclick="return confirm(\'您确定要删除吗?\')">删除</a></td>	
						</tr>';
}
$tmp_arr['tcount']=$pcount;
$tmp_arr['ttitle']=getmenu($GLOBALARR['menu'],'articlelist');
$tmp_arr['tpage']=$pagearr[0];
admin_two($tmp_arr);

?>